package com.example.test_1;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class demoEditText extends AppCompatActivity {

    private EditText editText,etUsername;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo_edit_text);


        /** setOnClickListener匿名内部类实现点击事件 */
/*        findViewById(R.id.Edit1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(demoEditText.this, "点击事件成功！！！", Toast.LENGTH_SHORT).show();
            }
        });*/


        editText = findViewById(R.id.Password);
        etUsername = findViewById(R.id.User);

    }

    public void login(View view) {
        String password = editText.getText().toString().trim();
        String User = etUsername.getText().toString().trim();

        //校验密码框的位数为6-12位
        if (password.length() >6 || password.length() <12){
            Toast.makeText(this, "密码为6-12位", Toast.LENGTH_SHORT).show();
            return;
        }
        if (TextUtils.isEmpty(password)){
            Toast.makeText(this, "密码不能为空", Toast.LENGTH_SHORT).show();
            return;
        }
        if (TextUtils.isEmpty(User)){
                Toast.makeText(this, "用户名不能为空", Toast.LENGTH_SHORT).show();
                return;
            }
            Toast.makeText(this, "登录成功", Toast.LENGTH_SHORT).show();
    }
}